<%@ page language="java" contentType="text/html; charset=UTF-8"  pageEncoding="UTF-8"%>
<!DOCTYPE HTML>
<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>添加和修改焦点图</title>
	<%@ include file="/view/common/tags.jsp"%>
</head>
<body>
	<div class="well well_p" >
		<sk:form method="post" cssClass="form-horizontal" action="" id="saveAndUpdateFrom" target="_parent" enctype="multipart/form-data">
			<div class="form-group">
				<label class="col-xs-3 text-right" >焦点图类型:</label>
	            <div class="col-xs-4 ">
	                <sk:select  cssClass="form-control select" id="foucsMapType" name="foucsMapType" value="" requiredInit="true" ajaxURL="${userInfoV1}/baseType/select?wm[TYPE_FLAG]=10&wm[OPEN_FLAG]=1&wm[DEL_FLAG]=0">
	                	<option value="">请选择</option>
	                </sk:select>
	            </div>
            </div>
            <div class="form-group">
				<label class="col-xs-3 text-right" >应用名称:</label>
	            <div class="col-xs-4 ">
		            <sk:select cssClass="form-control select" name="appId" id="appId" value="0" requiredInit="true" ajaxURL="${userInfoV1}/baseAppInfo/select?wm[DEL_FLAG]=0">
						<option value="0">全部</option>
					</sk:select>
                    <input type="hidden" id="appName" name="appName" value=""/>
	            </div>
            </div>
            <div class="form-group">
                <label class="col-xs-3 text-right">游戏名称:</label>
                <div class="col-xs-4 ">
                    <sk:select cssClass="form-control select" name="gameId" id="gameId" value="0" requiredInit="true" ajaxURL="${userInfoV1}/baseGame/gameSelect?wm[DEL_FLAG]=1">
						<option value="0" >全部</option>
                    </sk:select>
                    <input type="hidden" name="gameName" id="gameName" value=""/>
                </div>
            </div>
			<div class="form-group" >
				<label class="col-xs-3 text-right">是否有链接:</label>
				<div class="col-xs-9">
					<td colspan="2">
	                   	<label for="port1"><input id="yse1" name="hasLinkFlag" type="radio" value="1"/>&nbsp;有链接</label>&nbsp;&nbsp;&nbsp;&nbsp;
	                   	<label for="no1"><input id="no1" name="hasLinkFlag" type="radio"  value="0"/>&nbsp;无链接</label>
	               	</td>
				</div>
			</div>
            <div class="form-group" id="divLink">
				<label class="col-xs-3 text-right">链接:</label>
				<div class="col-xs-9">
					<input id="linkAddr" name="linkAddr" style="width:400px;height:30px;border:#ccc solid 1px;text-indent:3px;padding-top:3px;" value="${mainImg.link}">
				</div>
			</div>
			<div class="form-group" >
				<label class="col-xs-3 text-right">是否下载:</label>
				<div class="col-xs-4">
					<td colspan="2">
	                   	<label for="port"><input id="yse2" name="remark" type="radio" value="download"/>&nbsp;是</label>&nbsp;&nbsp;&nbsp;&nbsp;
	                   	<label for="no"><input id="no2" name="remark" type="radio" value="0"/>&nbsp;否</label>
	               	</td>
				</div>
			</div>
			<div class="form-group" >
				<label class="col-xs-3 text-right">是否发布:</label>
				<div class="col-xs-4">
					<td colspan="2">
	                   	<label for="port"><input id="yse" name="fbFlag" type="radio"  value="1"/>&nbsp;是</label>&nbsp;&nbsp;&nbsp;&nbsp;
	                   	<label for="no"><input id="no" name="fbFlag" type="radio" value="0"/>&nbsp;否</label>
	               	</td>
				</div>
			</div>
			<div class="form-group" >
			    <label class="col-xs-3 text-right">排序编号:</label>
				<div class="col-xs-4">
					<input id="orderByNo" name="orderByNo" value="" class="form-control">
				</div>
			</div>
			<div class="form-group" >
				<label class="col-xs-3 text-right">焦点图:</label>
				<div class="cb_box cbx_img_bg col-xs-9">
	    			<img id="newmainImgPath" src="" width="160px;" height="118px;" onerror="javascript:this.src='${sysManagerV1}/images/uploadImage/noimage.gif';">
		        	<br/>
		        	<div class="mainImgPathBox">
		        		<a href="javascript:;" class="file">选择文件<input id="Filedata" type="file" name="Filedata" onchange="newPic(this,'mainImgPath');"/></a>		        		
		        	</div>
		        	<div class="exp_box" style="color:red;">建议尺寸为285*169px(jpg、bmp、png等)，并且小于500KB的图片。</div>
               	</div>
			</div>
			<input type="hidden" id="imgPath" name="imgPath" value="">
			<input type="hidden" id="rowId" name="rowId" value="<%=request.getParameter("rowId")%>">
            <input type="hidden" id="flag"  value="<%=request.getParameter("flag")%>">
            <input type="hidden" id="token" name="token" value="">
			<input type="hidden" id="isReCommit" value="0">
		</sk:form>
	</div>
</body>
<%@ include file="/view/common/footer.jsp"%>
<script type="text/javascript">
$(function(){
    $("#token").val(sessionStorage.getItem("token"));
    
    var rowId = $("#rowId").val();
    if(rowId >= 0){
        $.ajax({
            url: "${userInfoV1}/baseFoucsMap/getInfo",
            type: "post",
            cache: false,
            data:{"rowId":rowId},
            dataType:"json",
            async:false,
            success: function(data) {
                if (data == null) {
                    return;
                }
                $("#foucsMapType").val(data.foucsMapType);
                $("#appId").val(data.appId);
                $("#appName").val(data.appName);
                $("#gameId").val(data.gameId);
                $("#gameName").val(data.gameName);
                $("#orderByNo").val(data.orderByNo);
                if(data.fbFlag == 1){
                    $("#yse").attr("checked","true");
                    $("#no").removeAttr("checked");
                } else {
                    $("#yse").removeAttr("checked");
                    $("#no").attr("checked","true");
                }
                
                if(data.remark == "download"){
                    $("#yse2").attr("checked","true");
                    $("#no2").removeAttr("checked");
                } else {
                    $("#yse2").removeAttr("checked");
                    $("#no2").attr("checked","true");
                }
                
                if(data.hasLinkFlag == 1){
                    $("#yse1").attr("checked","true");
                    $("#no1").removeAttr("checked");
                    
                    $("#linkAddr").val(data.linkAddr);
                    $('#divLink').show();
                } else {
                    $("#yse1").removeAttr("checked");
                    $("#no1").attr("checked","true");
                    $('#divLink').hide();
                }
                $("#hasLinkFlag").val(data.hasLinkFlag);
                if(data.imgPath != ""){
                    $("#newmainImgPath").attr("src", data.imgPath);
                } else {
                    $("#newmainImgPath").attr("src", "${sysManagerV1}/images/uploadImage/noimage.gif");
                }
                $("#imgPath").val(data.imgPath);
            }
        });
    }
})

//复选框点击事件(链接地址输入框的动态切换)
$("input[name='hasLinkFlag']:radio").click(function(){
    if ($(this).val() == 0) {
        $('#divLink').hide();
    } else {
        //当该焦点图没有链接是，点击有链接选项给链接输入框一个默认值(和添加的时候一样)
        var mainImgLink = $("#mainImgLink").val();
        if (mainImgLink == null || mainImgLink == '') {
            $("#link").attr("value", "https://");
        }
        $('#divLink').show();
    }
});

var err = {'1':'添加','2':'修改'};
var action = {'1':'/save','2':'/update'};
function add(){
    var rowId = $('#rowId').val();
    var i;
    if (!CheckUtil.isNotNull(rowId) || rowId == 0) {
        i = 1;//添加
    } else {
        i = 2;//修改
    }
    var mainImgName = $('#mainImgName').val();
    
    var foucsMapType = $('#foucsMapType').val();
    if (!CheckUtil.isNotNull(foucsMapType)) {
        layer.msg("请选择焦点图类型!");
        return;
    }
    var appId = $("#appId").val();
    var gameId = $("#gameId").val();
    if (!CheckUtil.isNotNull(appId) || !CheckUtil.isNotNull(gameId)) {
        layer.msg("应用名称和游戏必选一个!");
        return;
    }
    var appName = $("#appId").find("option:selected").text();
    $("#appName").val(appName);
    var gameName = $("#gameId").find("option:selected").text();
    $("#gameName").val(gameName);
    
    var linkFlag =$('input:radio[name="hasLinkFlag"]:checked').val();
    if (linkFlag == 1) {
        var linkAddr = $('#linkAddr').val();
        //去空格
        $('#linkAddr').val(CheckUtil.trim(linkAddr));
        //截取http：//后的字符串判断是否输入链接
        var str = linkAddr.substr(linkAddr.indexOf('https://')+8, linkAddr.length);
        if (!CheckUtil.isNotNull(str)) {
            layer.msg("请输入链接!");
            return;
        }
        if (str.indexOf('.') == -1) {
            layer.msg("请输入正确的链接!");
            return;
        }
    }
    //参数一系列校验
    var fbFlag =$('input:radio[name="fbFlag"]:checked').val();
    if (!CheckUtil.isNotNull(fbFlag)) {
        layer.msg("请选择是否发布!");
        return;
    }
    var orderByNo = $('#orderByNo').val();
    if (!CheckUtil.isNotNull(orderByNo) || !CheckUtil.isInt(orderByNo, "+") || orderByNo == 0) {
        layer.msg("请输入正确的排序编号!");
        return;
    }
    var imgPath = $("#imgPath").val();//图片
    if (flag == 0) {//添加的时候
        if (!CheckUtil.isNotNull(imgPath)) {
            layer.msg("请选择所要上传的图片!");
            return;
        }
        if (CheckUtil.isNotNull(imgPath) && !CheckUtil.isImg(imgPath)) {
            layer.msg("上传文件只能为图片!");
            return ;
        }
    } else {
        if (CheckUtil.isNotNull(imgPath)) {
            if (!CheckUtil.isImg(imgPath)) {
                layer.msg("上传文件只能为图片!");
                return ;
            }
        }
    }

    //loading层
    var index = layer.load(0, {
        shade: [0.1,'#fff'] //0.1透明度的白色背景
    });
    
    $.ajax({
        url: "${userInfoV1}/baseFoucsMap" + action[i],
        type: "post",
        cache: false,
        data: new FormData($("#saveAndUpdateFrom")[0]),
        dataType:"json",
        processData: false,
        contentType: false,
        async:false,
        success: function(data) {
            layer.close(index);
            if(data.code == 0){
                parent.layer.msg("添加成功！");
            } else if(data.code == 1){
                parent.layer.msg("修改成功！");
            } else if(data.code == "-2"){
                parent.window.location.href="${sysManagerV1}/";
            } else {
                parent.layer.msg(data.message);
            }
            if(data.code >= 0){
                parent.findData();
                parent.layer.close(parent.tableIndex);
            }
        }
    });
}

</script>
</html>